package com.chencs.biz.upload.controller;

import com.chencs.qiniu.UploadDemo;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import javax.servlet.http.HttpServletRequest;
import java.util.UUID;

/**
 * Created by fangzehua on 2017/8/3.
 */


@RequestMapping("/upload")
@RestController
public class UpLoadController {


    @RequestMapping(value = "/special", method = RequestMethod.POST)
    public String testUploadFile(HttpServletRequest req,
                               MultipartHttpServletRequest multiReq) {
        // 获取上传文件的路径
     try {
         MultipartFile file = multiReq.getFile("fileToUpload");
         UploadDemo demo = new UploadDemo(file.getBytes(), UUID.randomUUID().toString());
            String  code =  demo.upload();
             return code;
         }catch (Exception e){
             return "-1";
         }

    }
}
